//
//  Weekday.swift
//  Library_y
//
//  Created by JC on 2023/6/6.
//

import Foundation

public class WeekDay {  }
extension WeekDay {
    
    // 星期数组
    public static let strArr = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
    
    // 数字转星期
    public static func toWeekday(by number: Int) -> String {
        switch number {
            case 1: return "周一"
            case 2: return "周二"
            case 3: return "周三"
            case 4: return "周四"
            case 5: return "周五"
            case 6: return "周六"
            case 7: return "周日"
        default: return ""
        }
    }
    
    // 星期数组转int数组
    public static func toInt(by weekdayStrArr: [String]) -> [Int] {
        var intMutArr: [Int] = []
        for i in 0..<weekdayStrArr.count {
            if weekdayStrArr[i] == "周一" {
                intMutArr.append(0)
            } else if weekdayStrArr[i] == "周二" {
                intMutArr.append(1)
            } else if weekdayStrArr[i] == "周三" {
                intMutArr.append(2)
            } else if weekdayStrArr[i] == "周四" {
                intMutArr.append(3)
            } else if weekdayStrArr[i] == "周五" {
                intMutArr.append(4)
            } else if weekdayStrArr[i] == "周六" {
                intMutArr.append(5)
            } else if weekdayStrArr[i] == "周日" {
                intMutArr.append(6)
            }
        }
        return intMutArr
    }
    
    // 星期数组 转 => "、"连接字符串
    public static func strArrToStr(by strArr: [String]) -> String {
        var str = ""
        for i in 0..<strArr.count {
            str = str + strArr[i] + (i == strArr.count - 1 ? "" : "、")
        }
        return str
    }
    
    // int数组转星期数组
    public static func toStr(by weekDayIntArr: [Int]) -> [String] {
        var strMutArr: [String] = []
        for i in 0..<weekDayIntArr.count {
            if weekDayIntArr[i] == 1 {
                strMutArr.append("周一")
            } else if weekDayIntArr[i] == 2 {
                strMutArr.append("周二")
            } else if weekDayIntArr[i] == 3 {
                strMutArr.append("周三")
            } else if weekDayIntArr[i] == 4 {
                strMutArr.append("周四")
            } else if weekDayIntArr[i] == 5 {
                strMutArr.append("周五")
            } else if weekDayIntArr[i] == 6 {
                strMutArr.append("周六")
            } else if weekDayIntArr[i] == 7 {
                strMutArr.append("周日")
            }
        }
        return strMutArr
    }
    
    // int数组 转 => "、"连接字符串
    public static func intArrToStr(by intArr: [Int]) -> String {
        return strArrToStr(by: toStr(by: intArr))
    }
}
